package com.perform.service.user;

import com.domain.entity.User;
import com.domain.po.UserPo;
import com.domain.vo.UserVo;
import com.perform.mapper.user.IUserMapper;
import com.perform.service.IUserService;
import com.utils.BeanUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author c-fanqj
 * @date 2022/8/23
 * @apiNote
 */
@Service
public class UserService implements IUserService {

    //@Autowired
    //@Resource
    //private UserMapper userMapper;

    @Resource
    private IUserMapper iUserMapper;

    @Override
    public UserVo findUserById(Integer id) {
        User user = iUserMapper.findUserById(id);
        UserVo userVo = BeanUtil.objects2obj(user, UserVo.class);
        return userVo;
    }

    @Override
    public String selectUserDetail(UserPo userPo) {
        User userEntity = userPo;
        User user;
        user = iUserMapper.selectByPrimaryKey(userEntity);
        if (user == null) {
            return "数据不存在！";
        }
        UserVo userVo = BeanUtil.objects2obj(user, UserVo.class);
        return userVo.toString();
    }

    @Override
    public List<User> findAllUsers() {
        return iUserMapper.findAllUsers();
    }

    @Override
    public int insertUser(User user) {
        return iUserMapper.insertUser(user);
    }
}
